;(function(doc, win, width){
    var docEl = doc.documentElement;
    var head = doc.getElementsByTagName("head")[0];
    var hFirst = head.firstChild || head.firstElementChild; 
    var cssEl = doc.createElement('style');
    //手机横屏，竖屏可在此处设置 
    var resizeEvt = 'orientationchange' in win ? 'orientationchange' : 'resize';
    var recalc = function() {   
        var x; 
        var n = win.devicePixelRatio;      
        if (n >= 3) {                
            x = 3;                    
        } else if (n >= 2){
            x = 2;
        } else {
            x = 1;
        }
        var clientWidth = docEl.clientWidth;           
        if (!clientWidth) return;
        var pxPerRem = 100*(clientWidth / width);
        cssEl.innerHTML = 'html{ font-size:' + pxPerRem + 'px!important; }';
        docEl.setAttribute("data-dpr", x);   //x 限制范围取值 1,2,3
        head.appendChild(cssEl);   
    };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window,750)
// 若初始化为 750px, 此时整个屏幕宽度为 7.5rem
// 若初始化为 640px,(document, window,640), 此时整个屏幕宽度为 6.4rem


//虚拟数据
var obj = {
  home:{
    title:"首页"
  },
  xxkk:{
    title:"学校概况",
    en:"ABOUT US",
    children:[
      { title:"学校简介", modal:"tem1" },
      { title:"校园风采", modal:"tem3" },
      { title:"领导班子", modal:"tem4" },
      { title:"精品课堂", modal:"tem7" },
      { title:"联系地址", modal:"tem6" }
    ]
  },
  xydt:{
    title:"校园动态",
    en:'CAMPUS DYNS',
    children:[
      { title:"校园选项1", modal:"tem1" },
      { title:"校园选项2", modal:"tem1" },
      { title:"校园选项3", modal:"tem1" }
    ]
  },
  jyyd:{
    title:"教育园地",
    en:'EDUCATION GARDEN',
    children:[
      { title:"精品课堂", modal:"tem7"  },
      { title:"教育选项2", modal:"tem1"  },
      { title:"教育选项3", modal:"tem1"  }
    ]
  },
  zsjy:{
    title:"招生就业",
    en:'ADMISSION OFF',
    children:[
      { title:"招生选项1", modal:"tem1" },
      { title:"招生选项2", modal:"tem1" },
      { title:"招生选项3", modal:"tem1" }
    ]
  },
  ssfc:{
    title:"师生风采",
    en:'TEA AND STU PRE',
    children:[
      { title:"领导班子", modal:"tem4" },
      { title:"师生选项2", modal:"tem1" },
      { title:"师生选项3", modal:"tem1" }
    ]
  },
  djgz:{
    title:"党建工作",
    en:'PARTY CONSTN',
    children:[
      { title:"党建选项1", modal:"tem1" },
      { title:"党建选项2", modal:"tem1" },
      { title:"党建选项3", modal:"tem1" }
    ]
  }
};
//顶部导航字符模板
function top_nav_listHTML(obj,bool){
  var topNav = '';
  for(var k in obj){
    if( obj[k].children ){ 
    topNav += `<li>
                  <a href="info_page.html#p=${k}/${obj[k].children[0].modal}/0" data-page="${k}"><span>${obj[k].title}</span></a>
                  <ul class="child-list">${
                    (function(){
                      var str =""
                      $.each(obj[k].children,function(i,v){
                        if(bool){
                          str += '<li><a href="info_page.html#p='+k+'/'+v.modal+'/'+i+'">'+v.title+'</a></li>'
                        }else{
                          str += '<li><a href="#p='+k+'/'+v.modal+'/'+i+'">'+v.title+'</a></li>'
                        }                                             
                      })  
                      return str;                  
                    })()
                  }
                  </ul>
                </li>`;
    }else{
      var topNav = '<li><a href="index.html" class="page-btns n-home active"><span>首 页</span></a></li>';
    }
  }
  return topNav;
}

// -----页面逻辑操作----------------------------------------------------------------------------------

$(function(){
  // 图片处理
  $(".dp-center").each(function(){
    var url = $(this).attr("src");
    $(this).parent().attr("style","background:url("+url+") center no-repeat;background-size:cover;");
    $(this).hide();
  })
  //用户登录
  $("#login_btn").click(function(){
    $('#myLgModal').modal({
        keyboard : true,
        show: true,
        moveable:true
    })
  })

  var lis = $(".top-nav>ul>li");
  function wid(){
    if( $("html").hasClass("screen-phone") ){
      $("#shipin video").attr("controls","controls");
      $("#shipin .play-btn").hide();
      lis.css("width","100%"); 
    }else{
      $("#shipin video").removeAttr("controls");
      $("#shipin .play-btn").show();
      lis.css("width",$(".top-nav>ul").width()/lis.length);       
    }          
  };
  wid();
  $(window).on("resize",function(){
    wid();
    evReset();
  });

  //处理导航栏鼠标移入,点击效果
  (window.evReset = function evReset(){          
    if( $("html").hasClass("screen-phone") ){   
      $(".top-nav").on("click","#top_nav_lists>li>a",function(event){         
        if( $("html").hasClass("screen-phone") && !$(this).hasClass("n-home") ){
          $("#top_nav_lists>li>a").removeClass("active");
          $("#top_nav_lists>li> ul").hide();
          $(this).addClass("active");
          $(this).next("ul").show();
          event.preventDefault();
        }
      });
      $(document).on("touchmove",".top-nav",function(e){
        $("html,body").css("overflow-y","hidden");
      }).on("touchend",".top-nav",function(){
        $("html,body").css("overflow-y","auto");
      })
    }else{
      $(".top-nav").off().on("mouseover","#top_nav_lists>li",function(){
        $(this).find("ul").show();
      }).on("mouseout","#top_nav_lists>li",function(){
        $(this).find("ul").hide();
      })  
      $("#top_nav_lists").off().on("mouseover","li>a",function(){
        $(this).addClass("act");
      }).on("mouseout","li>a",function(){
        $(this).removeClass("act");
      })  
    }
  })();

  //移动端导航载入,载出事件
  $(".phone-tapNav-icon").click(function(){
    if( $(".top-nav").css("display") == "none" ){
      $(".top-nav").show().animate({right:0},100);
    }else{
      $(".top-nav").animate({right:'-50%'},100,function(){
        $(this).hide();
      });
    }
  });

  //搜索按钮
  $("#top_search_btn").click(function(){
    var value = $.trim( $("#top_search_input").val() );
    if(value){
      window.location.href = "search_result_page.html"
    }
  })  

  //页面显示
  $("body").animate({opacity:1},'fast');
})

// window.onload = function(){
//   $("body").animate({opacity:1},'fast');
// }